Code Scanning
# Create Code Scan
Request
POST /openapi/quality/codescan
1
Body Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
project_key | Project Key | string | Yes |
name | Code scan name | string | Yes |
description | Code scan description | string | No |
scanner_type | Code scan tool, two options: sonarQube, other | string | Yes |
image_name | Image name for scan environment | string | Yes |
sonar_system | SonarQube system identifier | string | Required if scanner_type = sonarQube |
repo_info | Repository information | []RepoInfo | Yes |
addons | Dependent package information, fill with empty array if not needed | []AddOn | Yes |
sonar_parameter | Code scan script | string | No |
script | Code scan script | string | No |
enable_quality_gate | Enable quality gate check | bool | Yes |
advanced_settings | Advanced settings | AdvancedSettings | Yes |
RepoInfo Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
codehost_name | Code source identifier | string | Yes |
repo_namespace | Repository namespace (organization/user) | string | Yes |
repo_name | Repository name | string | Yes |
branch | Branch information | string | Yes |
AddOn Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
name | Package name | string | Yes |
version | Package version | string | Yes |
AdvancedSettings Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
cluster_name | Cluster name in resource configuration | string | Yes |
timeout | Timeout in policy configuration | int | Yes |
resource_spec | Resource configuration | ResourceSpec | Yes |
webhooks | Trigger configuration | Webhooks | No |
ResourceSpec Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
cpu_limit | Max CPU resource, unit: m | int | Yes |
memory_limit | Max memory resource, unit: Mi | int | Yes |
cpu_request | Min CPU resource, unit: m | int | Yes |
memory_request | Min memory resource, unit: Mi | int | Yes |
Webhooks Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
enabled | Whether to enable trigger | bool | Yes |
hook_list | Trigger configuration details | []Hook | Required if enabled = true |
Hook Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
codehost_name | Code source identifier | string | Yes |
repo_namespace | Repository namespace (organization/user) | string | Yes |
repo_name | Repository name | string | Yes |
branch | Target branch information | string | Yes |
events | Trigger event types: push, pull_request, tag | []string | Yes |
match_folders | File directories | []string | Yes |
Body Parameter Example
{
"project_key": "demo",
"name": "codescan-demo",
"description": "code scan demo description",
"scanner_type": "sonarQube",
"sonar_system": "my-sonar",
"image_name": "sonar:v1",
"repo_info": [
{
"codehost_name": "github-demo",
"repo_namespace": "kr-test-org",
"repo_name": "zadig",
"branch": "main"
}
],
"sonar_parameter": "sonar.projectKey=zadig\nsonar.projectName=zadig\nsonar.sources=./cmd/aslan",
"enable_quality_gate": true,
"advanced_settings": {
"cluster_name": "dev-cluster",
"timeout": 60,
"resource_spec": {
"cpu_limit": 1000,
"memory_limit": 1000,
"cpu_request": 500,
"memory_request": 500
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Response
{
"message": "success"
}
1
2
3
2
3
# Execute Code Scan Task
Request
POST /openapi/quality/codescan/:scanName/task?projectKey=<projectKey>
1
Query Parameter Description
| Parameter Name | Type | Description | Required |
|---|---|---|---|
projectKey | string | Project Key | Yes |
Path Parameter Description
| Parameter Name | Type | Description | Required |
|---|---|---|---|
scanName | string | Code scan name | Yes |
Body Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
scan_repos | Repository info | []Repo | Yes |
Repo Parameter Description
| Parameter Name | Description | Type | Required |
|---|---|---|---|
branch | Branch name | string | Yes |
repo_name | Repository name | string | Yes |
repo_owner | Organization/User name | string | Yes |
source | Supported code repository sources:github, gitlab, gerrit, codehub, gitee, gitee-enterprise, other | string | Yes |
prs | PR number list | []int | No |
Body Parameter Example
{
"scan_repos":[
{
"branch":"master",
"repo_name":"voting-app",
"repo_owner":"kr-test-org1",
"source":"gitlab",
"prs":[]
}
]
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Success Response
| Parameter Name | Type | Description |
|---|---|---|
task_id | int | Code scan task ID |
{
"task_id": 27
}
1
2
3
2
3
Failure Response
{
"code": 500,
"description": "mongo: no documents in result",
"message": "Internal Error: "
}
1
2
3
4
5
2
3
4
5
# Get Code Scan Task Details
Request
GET /openapi/quality/codescan/:scanName/task/:taskID?projectKey=<projectKey>
1
Path Parameter Description
| Parameter Name | Type | Description | Required |
|---|---|---|---|
scanName | string | Code scan name | Yes |
taskID | int | Code scan task ID | Yes |
Query Parameter Description
| Parameter Name | Type | Description | Required |
|---|---|---|---|
projectKey | string | Project Key | Yes |
Success Response
| Parameter Name | Type | Description |
|---|---|---|
scan_name | string | Code scan name |
creator | string | Task creator |
create_time | int | Task creation time |
end_time | int | Task end time |
task_id | int | Code scan task ID |
status | string | Execution result |
result_link | string | Execution result link |
repo_info | []Repo | Repository info |
Repo Parameter Description
| Parameter Name | Description | Type |
|---|---|---|
branch | Branch name | string |
repo_name | Repository name | string |
repo_owner | Organization/User name | string |
source | Supported code repository sources:github, gitlab, gerrit, codehub, gitee, gitee-enterprise, other | string |
Response Example
{
"scan_name": "test",
"creator": "admin",
"task_id": 10,
"status": "running",
"create_time": 1689898942,
"end_time": 1689898944,
"result_link": "http://124.23.**.196:9009",
"repo_info": [
{
"repo_owner": "kr-test-org1",
"source": "gitlab",
"address": "https://gitlab.com",
"branch": "main",
"repo_name": "microservice-demo",
}
]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Failure Response
{
"code": 500,
"description": "mongo: no documents in result",
"message": "Internal Error: "
}
1
2
3
4
5
2
3
4
5


